package cn.itrip.auth.service;

import com.cloopen.rest.sdk.CCPRestSmsSDK;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @Author: jxm
 * @Description:
 * @Date: 2020/3/12 12:37
 * @Version: 1.0
 */
@Service("smsService")
public class SmsServiceImpl implements SmsService {

    @Override
    public void send(String to, String templateId, String[] datas) throws Exception {
        CCPRestSmsSDK sdk = new CCPRestSmsSDK();
        //初始化url
        sdk.init("app.cloopen.com","8883");
        //设置账号id 和token id
        sdk.setAccount("8aaf070870c2d02a0170ccc053c90582","a07657d730b242ea87a0515ffcae7507");
        //设置APP ID
        sdk.setAppId("8aaf070870c2d02a0170ccc056fe0589");

        HashMap result = sdk.sendTemplateSMS(to, templateId, datas);

        if("000000".equals(result.get("statusCode"))){ //发送成功
            System.out.println("短信发送成");
        }else{
            throw new Exception(result.get("statusCode").toString()+":"
                    +result.get("statusMsg").toString());
        }
    }
}
